/**
 * Created by hp on 2018/12/3.
 */
$(function () {
    $("#province").cityPicker({
        title: "选择城市",
        toolbarCloseText: "完成",
        onChange: function (picker, values, displayValues) {
            $("#city").val(values[1]);
            $("#district").val(values[2]);
            $.ajax({
                type: "POST",
                url: "/wechatOpportunity/wxGetAccount",
                data: {
                    city: $("#city").val(),
                    district: $("#district").val(),
                },

                success: function (data) {
                    if (data.status == "success") {
                        var accountList = data.accountList;
                        if (accountList.length > 0) {
                            $(".accountList").html("");
                            for (var i = 0; i < accountList.length; i++) {

                                var option = '<option>' + accountList[i] + '</option>';
                                $(".accountList").append(option);
                            }

                        }
                    }
                    else {
                        console.log("获取地址返回异常：" + data.errorMsg);
                    }
                },
                error: function () {
                    console.log("获取地址数据请求失败");
                }
            })
        }

    });

    // 参数合法性校验

    $("#wxcreate3Step1Btn").click(function () {

        var fullNameStr = $("#fullName").val().trim();
        var cellphoneStr = $("#cellphone").val().trim();
        if (!fullNameStr) {
            helpMessage("请输入姓名");
            return;
        }
        if (!(/^[\u2190-\u9fff]{1,10}$|^[\dA-Za-z]{1,20}$/.test(fullNameStr))) {
            helpMessage("姓名格式不正确");
            return;
        }
        if (!cellphoneStr) {
            helpMessage("请输入手机号");
            return;
        }
        if (!(/^(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$/.test(cellphoneStr))) {
            helpMessage("请输入正确的手机号");
            return;
        }

        var loanType = $("#loanType").val();
        if (!loanType) {
            helpMessage("请选择贷款类型");
            return;
        }

        var requestedAmount = $("#requestedAmount").val();
        if (!requestedAmount) {
            helpMessage("请输入贷款金额");
            return;
        }
        var city = $("#city").val().trim();
        if (!city) {
            helpMessage("请输入所在城市");
            return;
        }

        // 所在区县
        var district = $("#district").val().trim();
        if (!district) {
            helpMessage("请输入所在区县");
            return;
        }

        var account = $("#account").val();
        if (!account) {
            helpMessage("请选择网点");
            return;
        }

        $(".wxCreate3Form1").submit();
    });
    function helpMessage(message) {
        $(".helpMsg").text(message).fadeIn(200);
        setTimeout(function () {
            $(".helpMsg").fadeOut(200);
        }, 2000);
    }
})